﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IssueItem.aspx.cs" Inherits="Main_Inventory_IssueItem"
    Culture="en-GB" EnableViewState="true" %>
<%@ Register src="~/User Controls/MathCaptcha.ascx" tagname="SumCaptchaControl" tagprefix="uc1" %>
<%@ Register TagPrefix="uc" Namespace="ASPNET_Captcha" Assembly="ASPNET_Captcha" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Styles/accounts.css" rel="stylesheet" type="text/css" />
    <script src="../../JavaScript/Commons.js" type="text/javascript"></script>
    <style type="text/css">
        .AutoExtender
        {
            margin: 0px;
            background-color: White;
            color: windowtext;
            border: 1px solid #006699;
            line-height: 18px;
            padding: 8px;
            border-width: 1px;
            border-style: solid;
            cursor: 'default';
            height: auto;
            min-height: 10px;
            font-family: Verdana, Helvetica, Sans-Serif;
            font-size: .8em;
            font-weight: normal;
            text-align: left;
            list-style-type: none;
        }
        .AutoExtenderList
        {
            border-bottom: solid 1px #006699;
            color: Maroon;
            padding: 1px;
        }
        .AutoExtenderHighlight
        {
            color: White;
            background-color: #006699;
            padding: 1px;
        }
        #Background
        {
            position: fixed;
            top: 0px;
            bottom: 0px;
            left: 0px;
            right: 0px;
            background-color: #E8EAEC;
            opacity: 0.5;
        }
        #Progress
        {
            position: fixed;
            top: 45%;
            margin-left: 350px;
            width: 300px;
            height: 50px;
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        function divExpandCollapse(divname) {
            var div = document.getElementById(divname);
            var img = document.getElementById('img' + divname);
            if (div.style.display == "none") {
                div.style.display = "inline";
                img.src = "../../Menu/images/minus.gif";
            }
            else {
                div.style.display = "none";
                img.src = "../../Menu/images/plus.gif";
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="SCM" runat="server">
        </asp:ScriptManager>        
        <acc:heading ID="header1" runat="server" HeadingText="Item Issue" />
        <div align="center">
            <asp:Label ID="lblmsg" runat="server" style="display:none;"></asp:Label>
        </div>        
        <asp:UpdateProgress DynamicLayout="false" AssociatedUpdatePanelID="UpdatePanel2"
            ID="UpdProgress" runat="server">
            <ProgressTemplate>
                <div id="Background" runat="server">
                </div>
                <div align="center" id="Progress">
                    <img src="../../Images/ajax-loader.gif" alt="progessbar" />
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:Panel ID="pnlslipdetail" runat="server" Visible="false" Width="45%" Style="margin-left: 30%;">
            <table width="100%" class="tablecontent">
                <tr>
                    <td class="headtd" colspan="3">
                        Issued Slip Detail
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;Slip No
                    </td>
                    <td>
                        <asp:TextBox ID="txtslipno" runat="server" CssClass="input" AutoPostBack="true" onKeyPress="return isNumberKey(this.id,event)"
                            OnTextChanged="txtslipno_TextChanged" Style="text-align: right;"></asp:TextBox>
                        <AjaxControl:AutoCompleteExtender ID="ACESlipno" runat="server" CompletionInterval="0"
                            CompletionListCssClass="AutoExtender" CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
                            CompletionListItemCssClass="AutoExtenderList" CompletionSetCount="20" DelimiterCharacters=";,"
                            EnableCaching="true" FirstRowSelected="false" MinimumPrefixLength="1" ServiceMethod="GetSlipNo"
                            ShowOnlyCurrentWordInCompletionListItem="true" TargetControlID="txtslipno">
                        </AjaxControl:AutoCompleteExtender>
                    </td>
                    <td>
                        <asp:Button ID="btnsubmit" runat="server" CssClass="button1" OnClick="btnsubmit_Click"
                            Text="Slip No" OnClientClick="return CheckSlipNo();" />
                        <script type="text/javascript">
                            function CheckSlipNo() {
                                if (document.getElementById("txtslipno").value == '') {
                                    alert("Please Enter the Slip No.");
                                    return false;
                                }
                            }
                        </script>
                    </td>
                </tr>
            </table>
        </asp:Panel>
        <br />
        <asp:Panel ID="pnldata" Visible="false" runat="server" Width="99%" CssClass="tablecontent">
            <table cellpadding="3" width="100%" cellspacing="0" class="tablecontent">
                <tr>
                    <td style="width: 16%;">
                        Requested Date
                    </td>
                    <td style="width: 21%;">
                        Requested By
                    </td>
                    <td style="width: 16%;">
                        Issue Date<span class="required">*</span>
                    </td>
                    <td style="width: 18%;">
                        Issue By
                    </td>
                    <td style="width: 16%;">
                        Issue To<span class="required">*</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="txtrequestedDate" runat="server" CssClass="input" Enabled="false"
                            ForeColor="Black" Width="80px" Height="18px"></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="txtRequestedBy" runat="server" CssClass="input" Enabled="false"
                            ForeColor="Black" Width="150px" Height="18px"></asp:TextBox>
                    </td>
                    <td>
                        <AjaxControl:CalendarExtender ID="CalIssueDate" runat="server" Format="dd/MM/yyyy"
                            PopupButtonID="btnIssueDate" TargetControlID="txtIssuedDate">
                        </AjaxControl:CalendarExtender>
                        <asp:TextBox ID="txtIssuedDate" runat="server" CssClass="input" Style="background-color: #EBEBE4;"
                            ForeColor="Black" onKeyPress="return false;" Height="17px"></asp:TextBox>
                        <asp:ImageButton ID="btnIssueDate" runat="server" ImageUrl="~/Images/calendar.gif"
                            Style="margin-top: 4px;" />
                    </td>
                    <td>
                        <asp:TextBox ID="txtissuedby" CssClass="input" Width="140px" Height="18px" runat="server"
                            onKeyPress="return false;" Style="background-color: #EBEBE4;"></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="txtissuedto" CssClass="input" runat="server" Height="18px"></asp:TextBox>&nbsp;
                        <AjaxControl:AutoCompleteExtender ID="ACE" runat="server" TargetControlID="txtissuedto"
                            ServiceMethod="IssuedTo" CompletionInterval="0" CompletionListCssClass="AutoExtender"
                            CompletionListHighlightedItemCssClass="AutoExtenderHighlight" CompletionListItemCssClass="AutoExtenderList"
                            CompletionSetCount="20" DelimiterCharacters=";," EnableCaching="true" FirstRowSelected="false"
                            MinimumPrefixLength="1">
                        </AjaxControl:AutoCompleteExtender>
                    </td>
                </tr>
                <tr>
                    <td class="headtd" colspan="5">
                        Request Item Detail
                    </td>
                </tr>
            </table>
            <asp:HiddenField ID="hidCounter" runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <table width="100%" id="tblissueqty" runat="server">
                        <tr>
                            <td style="width: 17%; text-align: center; border: 1px solid gray;">
                                Item Code
                            </td>
                            <td style="width: 17%; text-align: center; border: 1px solid gray;">
                                Item Desc
                            </td>
                            <td style="width: 10%; text-align: center; border: 1px solid gray;">
                                RO#
                            </td>
                            <td style="width: 10%; text-align: center; border: 1px solid gray;">
                                Customer
                            </td>
                            <td style="width: 10%; text-align: center; border: 1px solid gray;">
                                Project Name
                            </td>
                            <td style="width: 8%; text-align: center; border: 1px solid gray;">
                                Stock Available
                            </td>
                            <td style="width: 7%; text-align: center; border: 1px solid gray;">
                                Request Qty
                            </td>
                            <td style="width: 7%; text-align: center; border: 1px solid gray;">
                                Issued Qty
                            </td>
                            <td style="width: 7%; text-align: center; border: 1px solid gray;">
                                Balance Qty
                                <script type="text/javascript">
                                    function CheckValue(RowId) {
                                        var Rownumber = RowId.replace(/[^\d.]/g, '');
                                        var BalanceQty = document.getElementById("txtBalanceQty" + Rownumber).value;
                                        var RequestBaseQty = document.getElementById("lblrequestqty" + Rownumber).value;
                                        var IssueQty = document.getElementById("txtIssueQty" + Rownumber).value;
                                        if (IssueQty == '') {
                                            alert("Please Check the Issue Item.");
                                            document.getElementById("txtIssueQty" + Rownumber).value = '0';
                                            return false;
                                        }
                                        var Stock = document.getElementById("txtAvailableqty" + Rownumber).value;

                                        if (IssueQty != "" && Stock != "") {
                                            if (Number(IssueQty) > Number(Stock)) {
                                                alert("You Cannot Enter Issue Qty Greater Than Available Stock.");
                                                document.getElementById("txtIssueQty" + Rownumber).value = '0';
                                                document.getElementById("txtIssueQty" + Rownumber).focus();
                                                return false;
                                            }
                                            if (Number(IssueQty) > Number(BalanceQty)) {
                                                alert("You Cannot Enter Issue Qty Greater Than Balance Qty. ");
                                                document.getElementById("txtIssueQty" + Rownumber).value = '0';
                                                document.getElementById("txtIssueQty" + Rownumber).focus();
                                                return false;
                                            }                                            
                                        }
                                    }
                                </script>
                            </td>
                            <td style="width: 7%; text-align: center; border: 1px solid gray;">
                                Issue Qty<span class="required">*</span>
                                <script type="text/javascript">
                                    function isNumber(evt) {
                                        var charCode = (evt.which)
                                        if (charCode == 46 || charCode == 47 || charCode == 44 || charCode == 59) {
                                            return false;
                                        }
                                        if (charCode > 65 && charCode < 91) {
                                            return false;
                                        }
                                        if (charCode > 95 && charCode < 121) {
                                            return false;
                                        }
                                    }
                                    function BalanceQty(row) {
                                        var BalanceQ = document.getElementById("txtBalanceQty" + row).value;
                                        var IssueQty = document.getElementById("txtIssueQty" + row).value;
                                        var Stock = document.getElementById("txtAvailableqty" + row).value;
                                        if (Number(IssueQty) <= Number(BalanceQ)) {
                                            var Balance = Number(BalanceQ) - Number(IssueQty);
                                            if (Number(IssueQty) > Number(Stock)) {
                                                alert("Issue Qty " + IssueQty + " is greater than Available Stock " + Stock + ".");
                                                document.getElementById("txtIssueQty" + row).value = '0';
                                                return false;
                                            }
                                            //document.getElementById("txtBalanceQty" + row).value = Balance;
                                        }
                                        else {
                                            alert("Issue Qty " + IssueQty + " is greater than Balance Available Qty " + BalanceQ + ".");
                                            document.getElementById("txtIssueQty" + row).value = '0';
                                            return false;
                                        }
                                    }
                                </script>
                            </td>
                        </tr>
                    </table>
                    <table width="100%" id="tblCaptcha" cellpadding="0" cellspacing="0" runat="server" visible="false">
                        <tr>                            
                            <td style="width:78%;" align="right">                                
                                <uc1:SumCaptchaControl ID="SumCaptchaControl1" runat="server" /> 
                            </td>
                            <td style="width:22%;">
                                <asp:Label ID="lblcaptchaerror" runat="server"></asp:Label>  
                            </td>                            
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <table width="100%">
                        <tr>
                            <td align="center">
                                <asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return CheckData();"
                                    OnClick="btnSave_Click" CssClass="button1" />
                                <script type="text/javascript">
                                    function CheckData() {
                                        var row = document.getElementById("hidCounter").value;
                                        var set = 0;
                                        if (document.getElementById("txtIssuedDate").value == '') {
                                            alert("Please Insert Issue Date.");
                                            document.getElementById("btnIssueDate").focus();
                                            return false;
                                        }
                                        else if (document.getElementById("txtissuedby").value == '') {
                                            alert("Please Insert Issued By Detail.");
                                            document.getElementById("txtissuedby").focus();
                                            return false;
                                        }
                                        else if (document.getElementById("txtissuedto").value == '') {
                                            alert("Please Insert Issued to Detail.");
                                            document.getElementById("txtissuedto").focus();
                                            return false;
                                        }
                                        for (var i = 1; i <= row; i++) {
                                            if (document.getElementById("txtIssueQty" + i).value == '') {
                                                //set = set + 1;
                                                alert("Enter the Qty for Issue Item.");
                                                return false;
                                            }
                                        }
                                    }
                                </script>
                                &nbsp;&nbsp;
                                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button1" OnClick="btnCancel_Click" />
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </asp:Panel>
        <asp:Panel ID="pnlview" runat="server" Visible="false" Width="99%" CssClass="tablecontent">             
            <div style="background-color: #EEEEEE; height: 25px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:80%;"></td>
                        <td style="width:10%;">
                            Search Slip No
                        </td>
                        <td style="width:5%;">
                            <asp:TextBox ID="txtslipnoSearch" runat="server" Width="120px" onFocus="resettext();" CssClass="input"></asp:TextBox>
                            <script type="text/javascript">
                                function resettext() {
                                    document.getElementById("lblmsg").style["display"] = 'none';
                                }
                            </script>
                        </td>
                        <td style="width:5%;">
                            <asp:Button ID="btnSearch" runat="server" CssClass="button" Text="Search" 
                                Width="60px" onclick="btnSearch_Click" OnClientClick="return ValidateSearch();" />
                            <script type="text/javascript">
                                function ValidateSearch() {
                                    if (document.getElementById("txtslipnoSearch").value == '') {
                                        document.getElementById("lblmsg").style["display"] = 'block';
                                        document.getElementById("lblmsg").style["color"] = '#B90000';
                                        document.getElementById("lblmsg").innerHTML = "Please Enter the Slip No.";
                                        return false;
                                    }
                                }
                            </script>
                        </td>
                    </tr>
                </table>
            </div>
            <asp:GridView ID="grdview" runat="server" AutoGenerateColumns="false" Width="100%"
                CssClass="gridview" OnPageIndexChanging="grdview_PageIndexChanging" AllowPaging="True"
                PageSize="20" DataKeyNames="ISSUEID" OnRowDataBound="grdview_RowDataBound">
                <Columns>
                    <asp:TemplateField HeaderText="S.No." ItemStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <%# Container.DataItemIndex+1 %>
                            <a href="Javascript:divExpandCollapse('div<%# Eval("ISSUEID") %>');">
                                <img id="imgdiv<%#Eval("ISSUEID") %>" width="9px" border="0" src="../../Menu/images/plus.gif" />
                            </a>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    </asp:TemplateField>
                    <asp:BoundField DataField="SLIPNO" HeaderText="Slip No" />
                    <asp:BoundField DataField="REQUESTEDATE" HeaderText="Requested Date" DataFormatString="{0:dd/MM/yyyy}" />
                    <asp:BoundField DataField="REQUESTEDBY" HeaderText="Requested By" DataFormatString="{0:0.00}" />
                    <asp:BoundField DataField="ISSUEDATE" HeaderText="Issue Date" DataFormatString="{0:dd/MM/yyyy}" />
                    <asp:BoundField DataField="ISSUEBY" HeaderText="Issue By" NullDisplayText="-----" />
                    <asp:BoundField DataField="ISSUETO" HeaderText="Issue To" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <tr>
                                <td colspan="100%">
                                    <div id="div<%# Eval("ISSUEID") %>" style="display: none; position: relative; left: 15px;
                                        overflow: auto">
                                        <asp:GridView ID="gvIssuItemChild" runat="server" CssClass="gridview" AutoGenerateColumns="false"
                                            Width="96%">
                                            <Columns>
                                                <asp:TemplateField HeaderText="S.No">
                                                    <ItemTemplate>
                                                        <%# Container.DataItemIndex+1 %>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="ItemCode" HeaderText="Item Code" />
                                                <asp:BoundField DataField="ItemDesc" HeaderText="Item Desc" />
                                                <asp:BoundField DataField="RO" HeaderText="Ro#" />
                                                <asp:BoundField DataField="CustomerName" HeaderText="Customer" />
                                                <asp:BoundField DataField="projectname" HeaderText="Project Name" />
                                                <asp:BoundField DataField="RequestQTY" HeaderText="Request Qty" ItemStyle-HorizontalAlign="Right" />
                                                <asp:BoundField DataField="IssueQty" HeaderText="Issue Qty" ItemStyle-HorizontalAlign="Right" />
                                            </Columns>
                                        </asp:GridView>
                                    </div>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </asp:Panel>
    </div>
    </form>
</body>
</html>
